// $Id: sessions.h 88 2011-10-17 18:00:11Z cedric.shih@gmail.com $
/*
 * Copyright 2011 Cedric Shih (cedric dot shih at gmail dot com)
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#ifndef SOURCES_H_
#define SOURCES_H_

#ifdef __cplusplus
extern "C" {
#endif

#include "session.h"

RB_HEAD(niortsp_session_tree, niortsp_session);

int niortsp_session_compare(
		struct niortsp_session *a,
		struct niortsp_session *b);

RB_PROTOTYPE(niortsp_session_tree, niortsp_session, next,
		niortsp_session_compare);

struct niortsp_sessions {
	struct niortsp_session_list list;
	struct niortsp_session_tree tree;
};

struct niortsp_sessions *niortsp_sessions_new(void);

void niortsp_sessions_free(struct niortsp_sessions *sessions);

int niortsp_sessions_add(struct niortsp_sessions *sessions,
		struct niortsp_session **out);

void niortsp_sessions_remove(struct niortsp_sessions *sessions,
		struct niortsp_session *entry);

struct niortsp_session *niortsp_sessions_find(
		struct niortsp_sessions *sessions, int fd);

void niortsp_sessions_clear(struct niortsp_sessions *sessions);

#ifdef __cplusplus
}
#endif

#endif /* SOURCES_H_ */
